﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using DTCash.Logger;
using DTCash.Logger.DTO;
using System.Text;

namespace Uranus.ChinaService
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            //log4net注册
            log4net.Config.XmlConfigurator.Configure();
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception exception = Server.GetLastError().GetBaseException();  //获取错误信息
            Common.VisitCommon info = new Common.VisitCommon();
            info.SetVisit(Request);

            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("[日志时间]：{0}", DateTime.Now.ToString());
            builder.AppendFormat("[客户端IP]：{0}\r\n", info.UserHostAddress);
            builder.AppendFormat("[服务器IP]：{0}\r\n", Common.VisitCommon.GetIp());
            builder.Append(exception.ToString());

            LogHelper.WriteLog(LogEnum.Error, "Uranus 汇付天下Service服务异常", builder.ToString(), true);
            Server.ClearError(); //清除异常，其他地方不再捕获此异常。
        }
    }
}